PWD:=$(shell pwd)

OUTPUT_DIR:=$(PREFIX)
LIB_NAME:=libtinyalsa

ifeq ($(LINKTYPE),shared)
CFLAGS := -fPIC
TARGET := $(LIB_NAME).so
else
TARGET := $(LIB_NAME).a
endif

ifeq ($(HOST),)
CROSS_COMPILE:=
else
CROSS_COMPILE:=$(HOST)-
endif

CC:=$(CROSS_COMPILE)gcc
AR:=$(CROSS_COMPILE)ar

all: ${TARGET}
INCS := asoundlib.h
SRCS := control.c mixer.c pcm.c
OBJS := $(addsuffix .o,$(basename ${SRCS}))

${LIB_NAME}.a:	${OBJS}
	$(AR) -r $(LIB_NAME).a ${OBJS}
	
${LIB_NAME}.so:	${OBJS}
	$(CC) -fPIC -shared -o $(LIB_NAME).so ${OBJS}

%.o : %.c
	${CC} -c ${CFLAGS} $< -o $@

install:
	-mkdir -p $(OUTPUT_DIR)/lib
	-mkdir -p $(OUTPUT_DIR)/bin
	-mkdir -p $(OUTPUT_DIR)/include
	cp $(TARGET) $(OUTPUT_DIR)/lib
	cp asoundlib.h $(OUTPUT_DIR)/include/
	
.PHONY: clean
clean:
	@rm -rf *.o *.a *.so